
public class Main {
public static final double e = 1e-14;
/*
 * EXAMPLE
  				4x -  y +  z =   15
  				4x - 8y +  z = -21
 			   -2x +  y + 5z =  15
 			   
 			   x = (7+y-z)/4
 			   y = (-21-z-4x)/-8
 			   z = (15+2x-y)/5
*/
	public static void main(String[] args) {
		double x = 1,y = 1,z = 1;
		boolean find = true;
		while(find)
		{
			x = (15.0+y-z)/4.0;
			y = (-21.0-z-4.0*x)/(-8.0);
			z = (15.0+2.0*x-y)/5.0;
			System.out.println(String.format("x = %.20f, y = %.20f, z = %.20f", x,y,z));
		find = checkPrecision(x,y,z);
		}
		System.out.println(String.format("x = %.14f, y = %.14f, z = %.14f", x,y,z));
		double a1 = 4.0*x-y+z;
		double a2 = 4.0*x-8.0*y+z;
		double a3 = -2.0*x+y+5.0*z;
		System.out.println(String.format("[  aprox]a1 = %.14f, a2 = %.14f, a3 = %.14f", a1,a2,a3));
		System.out.println(String.format("[correct]a1 = %.14f, a2 = %.14f, a3 = %.14f", 15.0,-21.0,15.0));
		
	}
private static boolean checkPrecision(double x, double y, double z) {
double a1 = 4.0*x-y+z;
double a2 = 4.0*x-8.0*y+z;
double a3 = -2.0*x+y+5.0*z;
double r1 = Math.abs(a1 - 15.0);
double r2 = Math.abs(a2 - (-21.0));
double r3 = Math.abs(a3 - 15);

if(r1 < e && r2 < e && r3 < e)
	return false;
else if(r1 == e && r2 == e && r3 == e)
	return true;
return true;
}

}
